package com.briup.product_my.controller;

import com.briup.product_my.domain.ManagerFenceHouse;
import com.briup.product_my.domain.ext.ManagerFenceHouseExt;
import com.briup.product_my.result.Result;
import com.briup.product_my.service.FenceHouseService;
import com.github.pagehelper.PageInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @Auther: xiongwenbin
 * @Date: 2024/8/21-08-21-下午6:25
 * @Description: com.briup.product_my.controller
 */
@RestController
@RequestMapping("/fenceHouse")
@Api(tags = "栏舍管理模块")
public class FenceHouseController {
    @Autowired
    private FenceHouseService fenceHouseService;
    //条件查询
    @ApiOperation(value = "条件查询栏舍信息")
    @GetMapping
    public Result getFenceHouse(@RequestParam(value = "fhName",required = false) String fhName,@RequestParam(value = "pageNum",required = false) Integer pageNum, @RequestParam(value = "pageSize",required = false) Integer pageSize){
        PageInfo<ManagerFenceHouse> result = fenceHouseService.findAll(fhName,pageNum,pageSize);
        return Result.success(result);
    }
    //根据id查询
    @ApiOperation(value = "根据id查询栏舍与栏圈信息")
    @GetMapping("/{fhId}")
    public Result getHurdlesByFhId(@PathVariable("fhId") String fhId){
        ManagerFenceHouseExt managerFenceHouse = fenceHouseService.findHurdlesById(fhId);
        System.out.println(managerFenceHouse);
        return Result.success(managerFenceHouse);
    }
    //新增或修改
    @ApiOperation(value = "新增或修改栏舍信息")
    @PostMapping("/saveOrUpdate")
    public Result saveOrUpdate(@RequestBody ManagerFenceHouse managerFenceHouse){
        fenceHouseService.saveOrUpdate(managerFenceHouse);
        return Result.success();
    }
    //删除
    @ApiOperation(value = "删除栏舍信息")
    @DeleteMapping("/{id}")
    public Result delete(@PathVariable("id") String id){

        return fenceHouseService.delete(id);
    }
    //批量删除
    @ApiOperation(value = "批量删除栏舍信息")
    @DeleteMapping("/deleteByIdAll")
    public Result deleteByIdAll(@RequestBody String[] ids){

        return fenceHouseService.deleteByIdAll(ids);
    }

    @ApiOperation(value = "查询所有栏圈")
    @GetMapping("/queryAll")
    public Result queryAll() {
        return Result.success(fenceHouseService.queryAll());
    }
}
